package com.mcr.graduateprogram.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.mcr.graduateprogram.bean.Others;
import com.mcr.graduateprogram.mapper.OthersMapper;
import com.mcr.graduateprogram.service.IOthersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author graduateprogram
 * @since 2023-02-25
 */
@Service
public class OthersServiceImpl extends ServiceImpl<OthersMapper, Others> implements IOthersService {
    @Autowired
    private OthersMapper othersMapper;

    @Override
    public int updateOthers(Others others) {
        LambdaUpdateWrapper<Others> othersLambdaUpdateWrapper=new LambdaUpdateWrapper<>();
        othersLambdaUpdateWrapper.set(others.getShowPhoto1()!=null,Others::getShowPhoto1,others.getShowPhoto1())
                                 .set(others.getShowPhoto2()!=null,Others::getShowPhoto2,others.getShowPhoto2())
                                 .set(others.getShowPhoto3()!=null,Others::getShowPhoto3,others.getShowPhoto3())
                                 .set(others.getTeachPhoto()!=null,Others::getTeachPhoto,others.getTeachPhoto())
                                 .set(Others::getCategoryId,others.getCategoryId())
        .set(others.getCategoryId()!=null&&others.getDiscount()>0&&others.getDiscount()<1,Others::getDiscount,others.getDiscount());
        return othersMapper.update(others, othersLambdaUpdateWrapper);
    }
}
